#region Using

using System;
using Microsoft.Xna.Framework;

#endregion

namespace XNgine.Util
{
    public static class MathUtil
    {
        public static Matrix CreateWorldMatrix(Vector3 Translation)
        {
            return CreateWorldMatrix(Translation, Quaternion.Identity);
        }
        public static Matrix CreateWorldMatrix(Vector3 Translation, Quaternion Rotation)
        {
            return CreateWorldMatrix(Translation, Rotation, Vector3.One);
        }
        public static Matrix CreateWorldMatrix(Vector3 Translation, Quaternion Rotation, Vector3 Scale)
        {
            return Matrix.CreateScale(Scale) *
                Matrix.CreateFromQuaternion(Rotation) *
                Matrix.CreateTranslation(Translation);
        }

        // Converts a rotation vector into a rotation matrix
        public static Matrix Vector3ToMatrix(ref Vector3 Rotation)
        {
            return Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z);
        }

        // Converts a rotation matrix into a rotation vector
        public static Vector3 MatrixToVector3(ref Matrix Rotation)
        {
            Quaternion q = Quaternion.CreateFromRotationMatrix(Rotation);
            return new Vector3(q.X, q.Y, q.Z);
        }

        public static bool IsInEpsilonDistance(Vector3 point1, Vector3 point2, float epsilon)
        {
            return Math.Abs(Vector3.Distance(point1, point2)) <= epsilon;
        }
    
    }
}